#ifndef DmCpta32H
#define DmCpta32H

#include <vcl\Classes.hpp>
#include <vcl\Controls.hpp>
#include <vcl\StdCtrls.hpp>
#include <vcl\Forms.hpp>
#include <vcl\DBTables.hpp>
#include <Db.hpp>

#include "Compta.h"
#include "CTable.h"
#include "compta.h"
#include "ctable.h"
#include "CptaAss.h"

class TdmCompta : public TDataModule
{
 __published:
    TTablePC *tblPC;
    TTableHI *tblHI;
    TTableHITmp *tblHITmp;
    TTableJnx *tblJnx;
    TStringField *tblPCCompte;
    TIntegerField *tblPCCycle;
    TIntegerField *tblPCTypeEnr;
    TStringField *tblPCIntitule;
    TStringField *tblPCIntituleLong;
    TBooleanField *tblPCLettrable;
    TBooleanField *tblPCSupprime;
    TIntegerField *tblPCVisa;
    TIntegerField *tblPCFlags;
    TCurrencyField *tblPCDebit;
    TCurrencyField *tblPCCredit;
    TCurrencyField *tblPCSoldeNm1;
    TCurrencyField *tblPCSoldeNm2;
    TStringField *tblHITmpCompte;
    TStringField *tblHITmpLibelleOperation;
    TCurrencyField *tblHITmpDebit;
    TCurrencyField *tblHITmpCredit;
    TIntegerField *tblHITmpIDLigne;
    TStringField *tblHITmpLettrage;
    TStringField *tblHITmpRAOData;
    TIntegerField *tblHITmpRAOIDLigne;
    TBooleanField *tblHITmpEstNouvelleLigne;
    TStringField *tblHITmpPiece;
    TIntegerField *tblPCDevise;
    TStringField *tblPCCompteO;
  TCurrencyField *tblPCDebitSit;
  TCurrencyField *tblPCCreditSit;
  TCurrencyField *tblPCDebitTotal;
  TCurrencyField *tblPCCreditTotal;
  TIntegerField *tblPCDrapeaux;
  TIntegerField *tblPCIDImage;
  TDateField *tblHIDateImputation;
  TAutoIncField *tblHIAutoID;
  TStringField *tblHICompte;
  TStringField *tblHICodeJournal;
  TStringField *tblHIPiece;
  TStringField *tblHILettrage;
  TSmallintField *tblHIFlagLettrage;
  TIntegerField *tblHIIDEcriture;
  TStringField *tblHILibelleOperation;
  TCurrencyField *tblHIMontantO;
  TIntegerField *tblHIDevise;
  TFloatField *tblHITaux;
  TCurrencyField *tblHIMontant;
  TBooleanField *tblHIEstCrediteur;
  TDateField *tblHIDateEcheance;
  TIntegerField *tblHIFlags;
  TIntegerField *tblHIIDImage;
  TSmallintField *tblHIModePaiement;
  TStringField *tblJnxCode;
  TStringField *tblJnxIntitule;
  TIntegerField *tblJnxNature;
  TIntegerField *tblJnxFlags;
  TStringField *tblHITmpDesignation;
  TStringField *tblHITmpCodeTVA;
  TFloatField *tblHITmpTauxTVA;
  TDateField *tblHITmpDateEcheance;
  TSmallintField *tblHITmpModePaiement;
  TStringField *tblHITmpBanque;
  TFloatField *tblHITmpQuantite;
  TIntegerField *tblHITmpIDParam;
  TIntegerField *tblHITmpFlagLettrage;
  TStringField *tblHITmpPieceExterne;
  TStringField *tblHITmpCodeAnalytik;
  TDateField *tblHITmpDateEP;
  TDateField *tblHIDateEP;
  TIntegerField *tblHIReviseur;
  TIntegerField *tblHIReference;
  TCurrencyField *tblPCSoldeNm3;
  TCurrencyField *tblPCSoldeNm4;
  TIntegerField *tblHITmpIDImage;
        CTable *tbl2H;
        TDataSource *DSHI;
        TIntegerField *tbl2HAutoID;
        TDateField *tbl2HRANDateO;
        TStringField *tbl2HRANJnlO;
        TStringField *tbl2HNaturePiece;
        TStringField *tbl2HPieceLiee;
        TStringField *tbl2HIDEcriturePart;
        TStringField *tbl2HRAOData;
        TIntegerField *tbl2HRAOIDLigne;
        TStringField *tbl2HCodeTVA;
        TFloatField *tbl2HTauxTVA;
        TStringField *tbl2HBanque;
        TFloatField *tbl2HQuantite;
        TStringField *tbl2HDesignation;
        TStringField *tbl2HPieceExt;
        TStringField *tbl2HCodeAnalytik;
        TQuery *qHI;
  TIntegerField *qHIIDEcriture;
  TStringField *qHICodeJournal;
  TBooleanField *tblHITmpIDImageModifie;
  TStringField *tblPCCompteAbrege;
  CTable *tblHITmpExport;
  TStringField *tblHITmpExportPiece;
  TStringField *tblHITmpExportCompte;
  TStringField *tblHITmpExportLibelleOpe;
  TCurrencyField *tblHITmpExportDebit;
  TCurrencyField *tblHITmpExportCredit;
  TDateField *tblHITmpExportDateOpe;
  TStringField *tblHITmpExportCodeJnl;
  TDateField *tblHITmpDateDebPeriode;
  TDateField *tblHITmpDateFinPeriode;
  TDateField *tbl2HDateDebPeriode;
  TDateField *tbl2HDateFinPeriode;
 private:
  int m_nNbOpenTables; // Nb de fois que les tables de la compta ont été "ouvertes logiquement"
 public:
  static TStringList *ComptesAvecMauvaiseClasse;
  __property int NbOpenCount = { read = m_nNbOpenTables};
  __fastcall TdmCompta();
  virtual __fastcall ~TdmCompta();
  void __fastcall OpenTablesCompta( bool bPourImport);
  void __fastcall CloseTablesCompta( void);
};



extern TdmCompta* _pdmCompta;
COMPTA32API void __fastcall OpenTables( bool bPourImport = false);
COMPTA32API void __fastcall CloseTables( void);
COMPTA32API void __fastcall EcritureOuvrir( const AnsiString& strJnl,
                                       const TDateTime&  dateImputation,
                                       int               nIDEcriture,
                                       bool              bPieceConst,
                                       const AnsiString& strPieceConst,
                                       bool              bContrepasser,
                                       unsigned int      eRAOIDEcriture);
COMPTA32API void __fastcall EcritureInsereLigne( const AnsiString&     strCompte,
                                            const AnsiString&     strLibelleOperation,
                                            const Currency&       curMontant,
                                            bool                  bIsDebiteur,
                                            const AnsiString&     strPiece,
                                            const AnsiString&     strLettrage,
                                            const CPTA_HIRAODATA* pcRAOData);
COMPTA32API void __fastcall EcritureValider( int                    nIdEcriture,
                                        enum TTableHI::HIFlags eHIFlagEcriture,
                                        CBarre*                pbarre);
COMPTA32API void __fastcall EcritureExporter(void);


#endif

